/*
 * ArrowDIamond.cpp
 *
 *  Created on: 14/07/2013
 *      Author: notebook
 */

#include "gui/VisualComponents/ArrowDiamond.h"

ArrowDiamond::ArrowDiamond(bool b_diamond) :
		ArrowHead(), line_color_("black"), fill_color_("white") {
	arrow_lenght_ = 10.0;
	is_black_diamond = b_diamond;
}

void ArrowDiamond::draw(Cairo::RefPtr< Cairo::Context > context_ref, double start_x, double start_y, double end_x, double end_y)
{
	int OFFSET = 3;
	double angle = atan2 (end_y - start_y, end_x - start_x) + M_PI;

	double x1 = end_x + arrow_lenght_ * cos(angle - arrow_degrees_);
	double y1 = end_y + arrow_lenght_ * sin(angle - arrow_degrees_);
	double x2 = end_x + arrow_lenght_ * cos(angle + arrow_degrees_);
	double y2 = end_y + arrow_lenght_ * sin(angle + arrow_degrees_);
	double x3 = end_x + arrow_lenght_ * 2 * cos(angle);
	double y3 = end_y + arrow_lenght_ * 2 * sin(angle);

	if(x3>x1){
		end_x += OFFSET;
		x1 += OFFSET;
		x2 += OFFSET;
		x3 += OFFSET;
	}
	if(x3<x1){
		end_x -= OFFSET;
		x1 -= OFFSET;
		x2 -= OFFSET;
		x3 -= OFFSET;
	}

	context_ref->move_to (end_x, end_y);
	context_ref->line_to (x1, y1);
	context_ref->line_to (x3, y3);
	context_ref->line_to (x2, y2);
	context_ref->close_path();
	if(is_black_diamond){
		context_ref->set_source_rgb (0.0, 0.0, 0.0);
		context_ref->fill();
	}

	context_ref->set_source_rgb (line_color_.get_red_p(), line_color_.get_blue_p(), line_color_.get_green_p());
	context_ref->stroke_preserve();

	context_ref->set_source_rgb (fill_color_.get_red_p(), fill_color_.get_blue_p(), fill_color_.get_green_p());
	context_ref->fill();
}
